package main

import (
	"context"
	"fmt"
	_ "github.com/mbobakov/grpc-consul-resolver" // It's important
	"go-grpc-lb/proto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
)

func main() {
	conn, err := grpc.Dial(
		"consul://10.0.0.102:8500/grpc_test?wait=14s&tag=lqz",
		grpc.WithTransportCredentials(insecure.NewCredentials()),
		grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy": "round_robin"}`),
	)

	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()
	client := proto.NewGreeterClient(conn)

	// 测试默认值
	resp, err := client.SayHello(context.Background(), &proto.HelloRequest{
		Name: "lqz",
		Age:  19,
	})

	if err != nil {
		panic(err)
	}
	fmt.Println(resp.Reply)
}
